<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增页面</title>
    <link rel="stylesheet" href="/component/pear/css/pear.css"/>
    <link rel="stylesheet" href="/admin/css/other/console1.css"/>
    <style>
        label.required:after { /* 给红色的必填项打红色星号（文字后）如果打前面用before*/
            content: ' *';
            color: red;
        }
        .layui-form-selectup dl {
            top: 42px;
            bottom: unset;
        }
        .layui-form-select dl {
            max-height: 260px;
        }
        .layui-disabled, .layui-disabled:hover{
            color: black !important;
        }

    </style>
</head>
<body class="pear-container" style="">
<form class="layui-form" action="" onsubmit="return false">
    <div class="layui-card">
        <div class="layui-card-body">
            <div class="layui-form-item">
                <label class="layui-form-label required">档案名称</label>
                <div class="layui-input-block">
                    <input type="text" name="fileName" required lay-verify="required" autocomplete="off"
                           th:value="${file_name}"
                           placeholder="请输入档案名称" disabled readonly
                           class="layui-input layui-disabled" lay-reqtext="档案名称为必填项">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">档案属性</label>
                <div class="layui-input-block">
                    <input type="text" name="fileAttributeName" autocomplete="off"
                           th:value="${file_attribute_name}"
                           placeholder="请输入档案属性"  disabled readonly
                           class="layui-input layui-disabled">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">
                    借阅部门
                </label>
                <div class="layui-input-block">
                    <input type="number" id="deptId" name="deptId" lay-verify="required"
                           lay-reqtext="借阅部门为必填项"
                           style="display:none;width: 0px" autocomplete="off" class="layui-input">
                    <ul id="dataTree" class="dtree" data-id="0"></ul>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">借阅人</label>
                <div class="layui-input-block">
<!--                    <select name="borrowers" lay-verify="required" lay-reqtext="借阅人为必填项" lay-search>-->
<!--                        <option value="">请选择借阅人</option>-->
<!--                        <option th:each="item,stat:${myUserList}" th:value="${item.userName}"-->
<!--                                th:text="${item.userName}"></option>-->
<!--                    </select>-->
                    <input type="text" name="borrowers" required lay-verify="required" autocomplete="off"
                           th:value="${userName}"
                           disabled readonly
                           class="layui-input layui-disabled" lay-reqtext="借阅人为必填项">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">借阅日期</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" autocomplete="off" lay-verify="required"
                           lay-reqtext="借阅日期为必填项" name="borrowingDate" id="borrowingDate">
                </div>
            </div>
<!--            <div class="layui-form-item">-->
<!--                <label class="layui-form-label required">审批人</label>-->
<!--                <div class="layui-input-block">-->
<!--                    <select name="approver" lay-verify="required" lay-reqtext="审批人为必填项" lay-search>-->
<!--                        <option value="">请选择审批人</option>-->
<!--                        <option th:each="item,stat:${myUserList}" th:value="${item.userName}"-->
<!--                                th:text="${item.userName}"></option>-->
<!--                    </select>-->
<!--                </div>-->
<!--            </div>-->
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">用途</label>
                <div class="layui-input-block">
                            <textarea name="purpose" placeholder="请输入此文档的用途" class="layui-textarea"
                                      style="min-height: 65px!important;"></textarea>
                </div>
            </div>
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                            <textarea name="remarks" placeholder="请输入备注" class="layui-textarea"
                                      style="min-height: 65px!important;"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">拟归还日期</label>
                <div class="layui-input-block">
                    <input type="text" class="layui-input" autocomplete="off" lay-verify="required"
                           lay-reqtext="归还日期为必填项" name="estimatedDate" id="estimatedDate">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn" lay-submit lay-filter="takeOutTheFileInfo">立即提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>
        </div>
    </div>
</form>

<script src="/component/layui/layui.js"></script>
<script src="/component/pear/pear.js"></script>
<script>
    layui.use(['form', 'jquery', 'laydate', 'dtree'], function () {
        let form = layui.form;
        let $ = layui.jquery;
        let laydate = layui.laydate;
        let dtree = layui.dtree;
        // 初始化树
        dtree.render({
            elem: "#dataTree",
            initLevel: "1",//默认展开层级为1
            width: "100%",
            method: 'get',
            dataStyle: "layuiStyle",  //使用layui风格的数据格式
            // response:{message:"msg",statusCode:200},  //修改response中返回数据的定义
            url: "/dept/buildDeptAll",
            dataFormat: "list",  //配置data的风格为list
            select: true, //指定下拉树模式
            selectTips: "请选择部门",
            selectCardHeight: "150"
        });
        dtree.on("node('dataTree')", function (obj) {
            var param = dtree.getNowParam("dataTree");
            $("#deptId").val(param.nodeId);
        });

        laydate.render({
            elem: '#estimatedDate' //指定元素
            , theme: '#393D49',
        });
        laydate.render({
            elem: '#borrowingDate' //指定元素
            , theme: '#393D49',
            max: maxDate(),
        });

        // 设置最大可选的日期
        function maxDate() {
            var now = new Date();
            return now.getFullYear() + "-" + (now.getMonth() + 1) + "-" + now.getDate();
        }

        form.on('submit(takeOutTheFileInfo)', function (data) {
            let loading = layer.load();
            $.ajax({
                url: '/file/manage/takeout/save',
                data: JSON.stringify(data.field),
                dataType: 'json',
                contentType: 'application/json',
                type: 'post',
                success: function (result) {
                    layer.close(loading);
                    if (result.code == 200) {
                        layer.msg(result.message, {icon: 1, time: 3000}, function () {
                            parent.layer.close(parent.layer.getFrameIndex(window.name)); //关闭当前页
                            parent.layui.table.reload("valid");
                        });
                    } else {
                        layer.msg(result.message, {icon: 2, time: 3000});
                    }
                }
            })
            return false;
        });
    })
</script>
<script>
</script>
</body>
</html>
